var success="\"\""; var question="\"\""; var error="\"\""; function getValues(sameDist){ var gasPriceHigh = 5.99; var gasPriceLow = 3.00; var frUNLV; var toUNLV; var same=false; // Check gas price if($('gasPriceIn').value.length>0){ $('gasPriceIcon').innerHTML=success; $('gasPriceMsg').innerHTML=""; var gasPriceIn=$('gasPriceIn').value; if(gasPriceIn > gasPriceHigh){ $('gasPriceIcon').innerHTML=question; $('gasPriceMsg').innerHTML="$"+gasPriceIn+" seems like an awful lot to pay for gas."; $('gasPriceMsg').style.display='block'; } else if(gasPriceIn < gasPriceLow){ $('gasPriceIcon').innerHTML=question; $('gasPriceMsg').innerHTML="$"+gasPriceIn+ " seems a little low for a gallon of gas."; $('gasPriceMsg').style.display='block'; } gasCalc=true; }else { gasCalc=false; $('gasPriceIcon').innerHTML=error; $('gasPriceMsg').style.display='none'; } // Check distances if($('toUNLV').value.length>0){ toUNLV = $('toUNLV').value; if($('same').checked){ same = true; //alert ('not checke'); frUNLV = toUNLV; frUNLVCalc = true; $('frUNLV').disabled=true; $('frUNLV').value=$('toUNLV').value; }else{ $('frUNLV').disabled=false; frUNLV = $('frUNLV').value; frUNLVCalc = false; } if(toUNLV>0){ if(toUNLV>100){ $('toUNLVIcon').innerHTML=question; $('toUNLVMsg').innerHTML="Please double check your distances and reenter if necessary"; }else{ $('toUNLVIcon').innerHTML=success; $('toUNLVMsg').innerHTML=""; } toUNLVCalc = true; }else{ $('toUNLVIcon').innerHTML=error; $('toUNLVMsg').innerHTML="Hey, this should be a number greater than 0!"; toUNLVCalc=false; } if(!same && $('frUNLV').value.length>0){ if(frUNLV>0){ if(frUNLV>100){ $('frUNLVIcon').innerHTML=question; $('frUNLVMsg').innerHTML="Please double check your distances and reenter if necessary"; }else{ $('frUNLVIcon').innerHTML=success; $('frUNLVMsg').innerHTML=""; } frUNLVCalc = true; }else{ $('frUNLVIcon').innerHTML=error; $('frUNLVMsg').innerHTML="Hey, this should be a number greater than 0!"; frUNLVCalc=false; } } }else{ $('toUNLVIcon').innerHTML=error; toUNLVCalc=false; } // Check MPG if($('mpg').value.length>0){ var mpg = $('mpg').value; if(mpg == 0){ $('mpgMsg').innerHTML="Sorry! Can't figure this out for cars that get "+mpg+" mpg."; $('mpgMsg').style.display='block'; $('mpgIcon').innerHTML=error; mpgCalc=false; }else{ if(mpg > 100){ $('mpgMsg').innerHTML="Wow! You shuold patent that car!"; $('mpgMsg').style.display='block'; $('mpgIcon').innerHTML=error; }else if(mpg > 40){ $('mpgMsg').innerHTML="Wow! That is excellent gas mileage, good for you."; $('mpgMsg').style.display='block'; $('mpgIcon').innerHTML=question; }else if($('mpg').value<8){ $('mpgMsg').innerHTML="Ouch! Do you have a Hummer?"; $('mpgMsg').style.display='block'; $('mpgIcon').innerHTML=question; }else{ $('mpgMsg').innerHTML=""; $('mpgMsg').style.display='none'; $('mpgIcon').innerHTML=success; } mpgCalc = true; } }else{ mpgCalc=false; $('mpg').innerHTML=error; $('mpg').style.display='block'; } // Check maint expenses if($('maint').value.length>0){ if($('maint').value>-1 && $('maint').value<2000){ $('maintIcon').innerHTML=success; $('maintMsg').innerHTML=''; maintCalc=true; }else{ $('maintIcon').innerHTML=success; $('maintMsg').innerHTML=''; maintCalc=false; } } // Check other if($('other').value.length>0){ if($('other').value>-1 && $('other').value<2000){ $('otherIcon').innerHTML=success; $('otherMsg').innerHTML=''; otherCalc=true; }else{ $('otherIcon').innerHTML=success; $('otherMsg').innerHTML=''; otherCalc=false; } } if(toUNLVCalc && frUNLVCalc && gasCalc && mpgCalc ){ //if(toUNLVCalc && frUNLVCalc && gasCalc && mpgCalc && maintCalc && otherCalc){ //alert (toUNLVCalc +" "+ frUNLVCalc +" "+ gasCalc +" "+ mpgCalc); displayTotal(); }else{ $('results').style.display = 'none'; } } function checkField(field){ field.value = field.value.replace(/[^0-9.]/g,''); //var t=setTimeout("getValues()",250); } function displayTotal(){ // Variables var numWeeksInSem = 15; var mpg = parseFloat($('mpg').value); var toDist = parseFloat($('toUNLV').value); var frDist = parseFloat($('frUNLV').value); var cost = parseFloat($('gasPriceIn').value); var maintIn = parseFloat($('maint').value); var other = 0; var dist = toDist+frDist; if($('other').value.length>0){ other = (parseInt($('other').value)) * (numWeeksInSem/52); }else{ //alert($('other').value.length); } //alert (cost); var maint = (maintIn * ((dist*15)/12000)) + other; var perDay = (dist * (1/mpg) * cost); var perClass = perDay * numWeeksInSem; var gas1 = perClass; var gas2 = perClass * 2; var gas3 = perClass * 3; var gas4 = perClass * 4; var gas5 = perClass * 5; var maint1 = maint; var maint2 = maint * 2 ; var maint3 = maint * 3; var maint4 = maint * 4; var maint5 = maint * 5; // Create result strings $('gas1').innerHTML=addCommas(gas1.toFixed(2)); $('gas2').innerHTML=addCommas(gas2.toFixed(2)); $('gas3').innerHTML=addCommas(gas3.toFixed(2)); $('gas4').innerHTML=addCommas(gas4.toFixed(2)); $('gas5').innerHTML=addCommas(gas5.toFixed(2)); $('maint1').innerHTML=addCommas(maint1.toFixed(2)); $('maint2').innerHTML=addCommas(maint2.toFixed(2)); $('maint3').innerHTML=addCommas(maint3.toFixed(2)); $('maint4').innerHTML=addCommas(maint4.toFixed(2)); $('maint5').innerHTML=addCommas(maint5.toFixed(2)); $('total1').innerHTML=addCommas((maint1 + gas1).toFixed(2)); $('total2').innerHTML=addCommas((maint2 + gas2).toFixed(2)); $('total3').innerHTML=addCommas((maint3 + gas3).toFixed(2)); $('total4').innerHTML=addCommas((maint4 + gas4).toFixed(2)); $('total5').innerHTML=addCommas((maint5 + gas5).toFixed(2)); // Display $('results').style.display = 'block'; /* troubleshooting alert ('dist: '+dist+' '+toDist+' '+frDist+' '+perDay); alert ('misc: '+maint1); alert ('mpg: '+mpg); perDay=$('gasPriceIn').value/$('mpg').value; perDay*=$('toUNLV').value*1+$('frUNLV').value*1; perDay+=$('other').value*1; perDay*=16; */ } function sameDistance(node){ if(node.checked){ $('frUNLV').value = $('toUNLV').value; $('frUNLV').disabled=true; $('frUNLVIcon').innerHTML=''; $('frUNLVMsg').innerHTML=''; } else { $('frUNLV').disabled=false; $('frUNLV').value = ''; $('frUNLVIcon').innerHTML=question; $('frUNLVMsg').innerHTML="Please add a value for your drive after your UNLV class."; } //alert ("leaving " + node.checked); getValues(node.checked); } function addCommas(nStr){ nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return "$" + x1 + x2; } function toggleButton(){ //alert('here'); $("learnMore").toggle(); }